#pragma once
#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <pthread.h>
#include <iostream>
#include <string>
#include <cstring>
#include <stdio.h>
#include "log.h"
#include "MvCameraControl.h"

extern const std::string executablePath;

bool PrintDeviceInfo(MV_CC_DEVICE_INFO *pstMVDevInfo);

// 海康相机类
class HikCamera
{
public:
    ~HikCamera();

    // 相机初始化
    bool CameraInit();
    // 设置相机采集图像的宽高
    bool SetWidthAndHeight(unsigned int Width, unsigned int Height);
    // 设置相机偏移量
    bool SetOffsetXAndOffsetY(unsigned int OffsetX, unsigned int OffsetY);
    // 开始取流
    bool StartGrabbing();
    // 获取一帧数据
    cv::Mat GetOneFrame();
    // 结束取流
    void StopGrabbing();
    // 将相机获取的数据保存为bmp图片
    void CloseCamera();
    bool writeForSaveImage(std::string file_path);

public:
    int m_nRet = MV_OK;
    unsigned int nIndex = 0;

    void *m_handle = NULL;
    unsigned char *pData = NULL;

    MV_CC_DEVICE_INFO_LIST m_stDeviceList;
    MVCC_INTVALUE m_stParam;
    MV_FRAME_OUT_INFO_EX stImageInfo = {0};

private:
    std::mutex mutex_; // 互斥锁
};
